//
//  CAEncryptedData.m
//  Test
//
//  Created by xgc on 12/25/17.
//  Copyright © 2017 xgc. All rights reserved.
//

#import "CAEncryptedData.h"

@implementation CAEncryptedData

+(id)initWithEncryptedData: (EncryptedData*)data{
    
    CAEncryptedData* encryptedData = [[CAEncryptedData alloc] init];
    
    vector<uint8_t> iv = data->getIV();
    
    encryptedData.initialisationVector = [[NSMutableData alloc]initWithBytes:&iv[0] length:iv.size()];
    
    vector<uint8_t> eBytes = data->getEncryptedBytes();
    
    encryptedData.encryptedBytes = [[NSMutableData alloc]initWithBytes:&eBytes[0] length:eBytes.size()];
    
    return encryptedData;
    
}

-(EncryptedData*) toEncryptedData {
    
    EncryptedData* encry = new EncryptedData();
    
    void *buffer = (void*)[self.initialisationVector bytes];
    size_t len = [self.initialisationVector length];
    
    vector<uint8_t> initialisationVector((uint8_t*)buffer, (uint8_t*)buffer + len);
    encry->setIV(initialisationVector);
    
    buffer = (void*)[self.encryptedBytes bytes];
    len = [self.encryptedBytes length];
    
    vector<uint8_t> encryptedBytes((uint8_t*)buffer, (uint8_t*)buffer + len);
    encry->setEncryptedBytes(encryptedBytes);
    
    return encry;
}

-(id)init {
    if (self = [super init]) {
        
    }
    return self;
}

@end
